﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;

using BLL;
using DAL;
using Models;
using System.Data;
using System.Text;
using System.Xml;
using Gift.WebApp;

public partial class backstage_system_notice : System.Web.UI.Page
{
    // Fields

    protected string systemNoticeXmlPath = "/cn/xml/system_notice.xml";
    // Methods
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            XmlDocument document = new XmlDocument();
            document.Load(base.Server.MapPath(this.systemNoticeXmlPath));
            XmlElement element = document.SelectSingleNode("notice") as XmlElement;
            element.InnerText = this.txtaNoticeTitle.InnerText;
            element.SetAttribute("url", this.txtUrl.Value);
            if (this.rdIsShow1.Checked)
            {
                element.SetAttribute("isShow", "true");
            }
            else
            {
                element.SetAttribute("isShow", "false");
            }
            document.Save(base.Server.MapPath(this.systemNoticeXmlPath));
            base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新成功！\");location.href=\"system_notice.aspx\";</script>");
        }
        catch
        {
            base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新失败！\");</script>");
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if ((HttpContext.Current.Session["admin_user"] == null) && (HttpContext.Current.Session["language_version"] == null))
        {
            base.ClientScript.RegisterStartupScript(base.GetType(), "sJs", "top.location=\"login.html\";", true);
        }
        if (!base.IsPostBack)
        {
            this.SystemNoticeBind();
        }
    }

    private void SystemNoticeBind()
    {
        try
        {
            XmlDocument document = new XmlDocument();
            document.Load(base.Server.MapPath(this.systemNoticeXmlPath));
            XmlElement element = document.SelectSingleNode("notice") as XmlElement;
            this.txtaNoticeTitle.InnerText = element.InnerText;
            this.txtUrl.Value = element.GetAttribute("url");
            if (element.GetAttribute("isShow") == "true")
            {
                this.rdIsShow1.Checked = true;
            }
            else
            {
                this.rdIsShow0.Checked = true;
            }
        }
        catch
        {
        }
    }

}